<div class="toolbar">
  <div class="toolbar-header">
    <%= "Invoice Code/Date: #{@invoice.code} / #{@invoice.date}" %>
  </div>
</div>

<ul class="nav nav-tabs">
  <li class="active"><a href="#invoice_detail" data-toggle="tab"><%= t :invoice_details_edit %></a></li>
  <li><a href="#payment_detail" data-toggle="tab"><%= t :payments %></a></li>
</ul>

<div class="tab-content">
  <div class="tab-pane active" id="invoice_detail">
    <div class="row toolbar">
	  <div class="col-md-6">
		<span class="toolbar-header">
		  <%= t :invoice_details_edit %>
		</span>
	  </div>
	  <div class="col-md-6 text-right">
		<ul class="toolbar-nav">
		  <li><%= link_to feather_icon('circle-plus'), new_invoice_invoice_detail_path(:invoice_id => params[:id]) %></li>
		  <li><% link_to simple_icon('note'), new_invoice_invoice_detail_path(:invoice_id => params[:id]) %></li> 
          <li><% link_to feather_icon('trash'), new_invoice_invoice_detail_path(:invoice_id => params[:id]) %></li>
		</ul>
	  </div>
	</div>
	<div class="row">
	 <div class="col-md-12">
		<strong>Code:</strong><%= @invoice.code %></br>
		<strong>Date:</strong><%= @invoice.date %>
	 </div>
	</div>
 
	<hr>
	<div class="row toolbar">
	 <div class="col-md-12">
		<span class="toolbar-header">
		  Add invoice details:
		</span>
	 </div>
	</div>
	<div class="row">
	 <div class="col-md-12">
		<%= render "invoice_details/form_sales" %>
	 </div>
	</div>
	
	<hr>
	<div class="row">
	 <div class="col-md-12">	
		<table class="table table-striped">
			<thead>
				<tr>
					<th><%= t :actions %></th>
					<th><%= t :drugs %></th>
					<th><%= t :quantities %></th>
					<th><%= t :fee %></th>
					<th><%= t :discount %></th>
				</tr>
			</thead>

			<tbody>
			<% @invoice_details.each do |fr| %>
				<tr>
				<td><%= link_to simple_icon('note'), edit_invoice_invoice_detail_path(:invoice_id => params[:id], :id => fr.id) %>
				<%= link_to feather_icon('trash'), [fr.invoice, fr], method: :delete, data: { confirm: 'Are you sure?' }%>
				</td>
				<td>
				<% fr.stock_logging.drugs.each do |d| %>
				<%= link_to d.name, drug_path(:id => fr.stock_logging.drug_id) %>
				<% end %>
				</td>
				<td><%= fr.stock_logging.try(:quantity) %></td>
				<td><%= fr.fee %></td>
				<td><%= fr.discount %></td>
				</tr>
				<% end %>
				<!--% render @invoice.invoice_details %-->
			</tbody>
		</table>
	 </div>
	</div>
	
	<hr>
	<div class="row">
	 <div class="col-md-12 text-right">
		<strong>Total <%= t :fee %>:</strong><%= @invoice.total_fee %></br>
		<strong>Total <%= t :discount %>:</strong><%= @invoice.total_discount %>
	 </div>
	</div>
  </div>
  	 
  <div class="tab-pane" id="payment_detail">
  <div class="row toolbar">
	  <div class="col-md-6">
		<span class="toolbar-header">
		  <%= t :payments %>
		</span>
	  </div>
	  <div class="col-md-6 text-right">
		<ul class="toolbar-nav">
		  <li><%= link_to feather_icon('circle-plus'), new_invoice_payment_path(:invoice_id => params[:id]) %></li>
        </ul>
      </div>
  </div>
  <table class="table table-striped">
      <thead>
		<tr>
		  <th><%= t :actions %></th>
		  <th><%= t :created_at %></th>
		  <th><%= t :payment_method %></th>
		  <th><%= t :card_number %></th>
		  <th><%= t :card_provider %></th>
		  <th><%= t :card_transaction_ref %></th>
		  <th><%= t :amount %></th>
		  <th><%= t :change %></th> 
		</tr>
	  </thead>
	  
	  <tbody>
          <%= render @invoice.payments %>	
      </tbody>
  </table>
  		
  </div>
</div>

